<div class="orders_control detail">
    <div class="back_control">
        <a class="controllbutton" href="<?php echo $this->url(array('action' => 'list', 'id' => null, 'to_status' => null))?>" 
            title="<?php echo $this->translate('TOOLTIP_STATUS_BACK')?>" id="btn_back">
            <span></span>
            <?php echo $this->translate('LABEL_STATUS_BACK')?>
        </a>
    </div>
    
    <div class="mark_controll" style="display: inline-block">
        <span class="controllbutton"><?php echo $this->translate('LABEL_ACTION_MARK_AS');?> <i></i></span>
        <div class="mark_action">
            <?php if($this->cart->status != Core_Model_DbTable_Carts::STATUS_UNREAD):?>
                <a href="<?php echo $this->url(array('action' => 'mark', 'back_action' => 'list', 'id_carts' => $this->cart->id, 'to_status' => Core_Model_DbTable_Carts::STATUS_UNREAD))?>" 
                    title="<?php echo $this->translate('TOOLTIP_STATUS_UNREAD')?>"><?php echo $this->translate('LABEL_ACTION_UNREAD')?></a>
            <?php endif;?>
            <?php if($this->cart->status != Core_Model_DbTable_Carts::STATUS_READ):?>
                <a href="<?php echo $this->url(array('action' => 'mark', 'back_action' => 'detail', 'id_carts' => $this->cart->id, 'to_status' => Core_Model_DbTable_Carts::STATUS_READ))?>" 
                    title="<?php echo $this->translate('TOOLTIP_STATUS_READ')?>"><?php echo $this->translate('LABEL_ACTION_READ')?></a>
            <?php endif;?>
            <?php if ($this->cart->status != Core_Model_DbTable_Carts::STATUS_RESOLVED):?>
                <a href="<?php echo $this->url(array('action' => 'mark', 'back_action' => 'detail', 'id_carts' => $this->cart->id, 'to_status' => Core_Model_DbTable_Carts::STATUS_RESOLVED))?>" 
                    title="<?php echo $this->translate('TOOLTIP_STATUS_RESOLVED')?>"><?php echo $this->translate('LABEL_ACTION_RESOLVE')?></a>
            <?php endif;?>
            
            <?php if($this->cart->is_important == Core_Model_DbTable_Carts::STATUS_UNIMPORTANT):?>
                <a class="mark_important" rel="<?php echo $this->url(array('action' => 'important', 'is_important' => Core_Model_DbTable_Carts::STATUS_IMPORTANT))?>" 
                    title="<?php echo $this->translate('TOOLTIP_STATUS_IMPORTANT')?>"><?php echo $this->translate('LABEL_ACTION_IMPORTANT')?></a>
            <?php else:?>
                <a class="mark_important" rel="<?php echo $this->url(array('action' => 'important', 'is_important' => Core_Model_DbTable_Carts::STATUS_UNIMPORTANT))?>" 
                    title="<?php echo $this->translate('TOOLTIP_STATUS_UNIMPORTANT')?>"><?php echo $this->translate('LABEL_ACTION_UNIMPORTANT')?></a>
            <?php endif;?>
        </div>
    </div>
    
    <div class="delete_control">
        <a class="controllbutton" id="delete_cart" rel="<?php echo $this->url(array('action' => 'mark', 'id_carts' => $this->cart->id, 'to_status' => Core_Model_DbTable_Carts::STATUS_DELETE))?>" 
            title="<?php echo $this->translate('TOOLTIP_STATUS_DELETE')?>"><?php echo $this->translate('LABEL_ACTION_DELETE')?></a>
    </div>
</div>
<script type="text/javascript">
    function getMessage(message){
        $(".msg_panel").remove();
        return '<div class="msg_panel"><p>' + message + '</p></div>';
    }
    $(document).ready(function(){
        $('#delete_cart').click(function(){
            var msg_confirm_delete_cart = '<?php echo $this->translate('MSG_CONFIRM_DELETE_CART')?>';
            if(confirm(msg_confirm_delete_cart)){
                location.href = $(this).attr('rel');
            }
        });
        $(".mark_important").click(function(){
            var url = $(this).attr("rel");
            var tooltip_important = "<?php echo $this->translate('TOOLTIP_STATUS_IMPORTANT')?>";
            var label_action_important = "<?php echo $this->translate('LABEL_ACTION_IMPORTANT')?>";
            var tooltip_unimportant = "<?php echo $this->translate('TOOLTIP_STATUS_UNIMPORTANT')?>";
            var label_action_unimportant = "<?php echo $this->translate('LABEL_ACTION_UNIMPORTANT')?>";
            $.ajax({
                url: url,
                data: {},
                success: $.proxy(function(respond){
                    var result = jQuery.parseJSON(respond);
                    if(result.success == true){
                        $(this).attr('rel', result.rel);
                        if(result.is_important == true){
                            $(this).text(label_action_unimportant);
                            $(this).attr('title', tooltip_important);
                        }
                        else{
                            $(this).text(label_action_important);
                            $(this).attr('title', tooltip_unimportant);
                        }
                    }
                    $(".order_detail").before(getMessage(result.message));
                },this)
            });
        });
    });
</script>
